var t = "", o = 0, e = 0, r = new Array(), a = 0, n = new Array(), tsxx2 = "等级测试", xpznr = new Array();
var app = getApp();

Page({
    data: {
        TabCur: 0,
        scrollLeft: 0,//导航栏
        DotStyle: true,
        cardCur: 0,//滑动
        sousuotext: "|搜索",
        tsxx: '热搜:方言等级测试',
        csnr: null,
        ssnr: null,
        jbdh: 1,
        fxnr: null,
        bnrUrl: null,
        flbq: ['全部', '性格', '心理', '情感', '趣味', '节日', '答题', '瓶子'],
        xpzcslb: false, xpzcslbs: true, //小瓶子测试列表
        bjys: '#cce6ff',
    },
    onLoad: function (s) {
        wx.showLoading({
            title: "加载中..."
        });
        a = 0, o = 0;
        var os = this;
        os.onPullDownRefresh();
        wx.request({
            url: app.globalData.url + "ndzscs/request1/mains.php",
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function (e) {
                app.globalData.fxnr = e.data;
                os.setData({
                    fxnr: e.data,
                })
            }
        })//判断是否提前加载成功
        wx.request({
            url: app.globalData.url + "ndzscs/request1/zst.php",
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function (e) {
                os.setData({
                    bnrUrl: [{
                        "url": e.data.tp1
                    }, {
                        "url": e.data.tp2
                    }, {
                        "url": e.data.tp3
                    }, {
                        "url": e.data.tp4
                    }]
                })
            },
        }); //获取展示图
        if (s.tm != null) {
            if (s.tm == 'yzcp') {
                wx.navigateTo({
                    url: "/pages/yzcp/yzcp"
                });
            } else if (s.tm == 'dcwj') {
                wx.navigateTo({
                    url: "/pages/questionnaire/questionnaire?num=" + s.num,
                });
            } else if (s.tm == 'wzyd') {
                wx.navigateTo({
                    url: "/pages/article/article?num=" + s.num,
                });
            }
            else {
                wx.navigateTo({
                    url: "/pages/ceshi/ceshi?tm=" + s.tm + "&tp=" + s.tp + "&bjtp=" + s.bjtp + "&xxjs=" + s.xxjs + "&num=" + s.num + "&xpzcs=" + s.xpzcs + "&zdy=" + s.zdy + "&csrs=" + s.csrs,
                });
            }
        } //界面跳转
        wx.hideLoading();
    },
    onPullDownRefresh: function () {
        var s = this;
        o = 0, r = new Array(), n = new Array(), wx.request({
            url: app.globalData.url + "ndzscs/request1/main.php",
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function (c) {
                app.globalData.csnr = c.data;
                for (i = 0; null != c.data[i]; i++) o += 1;
                if (0 == a)
                    for (i = 10; a < i; a++) r[a] = c.data[a];
                else {
                    for (var i = 0; i < a; i++) r[i] = c.data[i];
                }
                n = c.data, s.setData({
                    csnr: r,
                    ssnr: null,
                    xpzcslb: false, xpzcslbs: true,
                    TabCur: 0,
                    scrollLeft: (-1) * 50,
                }), t = "", e = 0
            },
            fail: function () {
                wx.showToast({
                    title: "连接服务器失败，请下拉刷新！",
                    icon: "none",
                    duration: 2e3
                });
            }
        }), wx.stopPullDownRefresh();
    },
    onReachBottom: function () {
        if (0 == e) {
            wx.showLoading({
                title: "加载中..."
            });
            var t = this;
            if (a < o)
                if (o - a >= 10) {
                    for (var s = a + 10; a < s; a++) r[a] = n[a];
                    t.setData({
                        csnr: r
                    });
                } else {
                    for (; a < o; a++) r[a] = n[a];
                    t.setData({
                        csnr: r
                    });
                }
            else wx.showToast({
                title: "没有更多测试了",
                icon: "none",
                duration: 800
            });
            wx.hideLoading();
        }
    },
    onShareAppMessage: function () { },
    kscs: function (t) {
        var o = t.currentTarget.dataset.index;
        wx.navigateTo({
            url: "/pages/ceshi/ceshi?tm=" + this.data.csnr[o][1] + "&tp=" + this.data.csnr[o][4] + "&bjtp=" + this.data.csnr[o][5] + "&xxjs=" + this.data.csnr[o][3] + "&num=" + this.data.csnr[o][0] + "&xpzcs=0" + "&zdy=" + this.data.csnr[o][10] + "&csrs=" + this.data.csnr[o][6]
        });
    },
    getInput: function (o) {
        t = o.detail.value;
    },
    cztm: function () {
        var o = this;
        if (t == '') {
            wx.request({
                url: app.globalData.url + "ndzscs/request1/sscs.php",
                data: {
                    tm: tsxx2
                },
                method: "GET",
                header: {
                    "content-type": "application/json"
                },
                success: function (t) {
                    "" == t.data ? wx.showToast({
                        title: "没有找到对应的测试！",
                        icon: "none",
                        duration: 2e3
                    }) : (e = 1, wx.showToast({
                        title: "搜索成功，点击全部返回！",
                        icon: "success",
                        duration: 2e3
                    }), o.setData({
                        csnr: t.data
                    }));
                },
                fail: function () {
                    wx.showToast({
                        title: "连接服务器失败，请重新查找！",
                        icon: "none",
                        duration: 2e3
                    });
                }
            });
            t = "";
        } else {
            wx.request({
                url: app.globalData.url + "ndzscs/request1/sscs.php",
                data: {
                    tm: t
                },
                method: "GET",
                header: {
                    "content-type": "application/json"
                },
                success: function (t) {
                    "" == t.data ? wx.showToast({
                        title: "没有找到对应的测试！",
                        icon: "none",
                        duration: 2e3
                    }) : (e = 1, wx.showToast({
                        title: "搜索成功，点击全部返回！",
                        icon: "success",
                        duration: 2e3
                    }), o.setData({
                        csnr: t.data
                    }));
                },
                fail: function () {
                    wx.showToast({
                        title: "连接服务器失败，请重新查找！",
                        icon: "none",
                        duration: 2e3
                    });
                }
            });
        }

    },
    kscs2: function (t) {
        var o = t.currentTarget.dataset.index;
        wx.navigateTo({
            url: "/pages/ceshi/ceshi?tm=" + this.data.fxnr[o][1] + "&tp=" + this.data.fxnr[o][4] + "&bjtp=" + this.data.fxnr[o][5] + "&xxjs=" + this.data.fxnr[o][3] + "&num=" + this.data.fxnr[o][0] + "&xpzcs=0" + "&zdy=" + this.data.fxnr[o][7] + "&csrs=null"
        });
    },
    qhssnr: function () {
        if (t == '' && n != null) {
            var nr = Math.floor(Math.random() * (o - 1));
            tsxx2 = n[nr][1];
            this.setData({
                tsxx: '热搜:' + n[nr][1]
            })
        }
    },
    cardSwiper(e) {
        this.setData({
            cardCur: e.detail.current
        })
    },//卡片滑动
    tabSelect(t) {
        var o = this;
        if (0 == t.currentTarget.dataset.id) o.onPullDownRefresh();
        else if (t.currentTarget.dataset.id == 7) {
            wx.request({
                url: app.globalData.url + "ndzscs/request1/main3.php",
                method: "GET",
                header: {
                    "content-type": "application/json"
                },
                success: function (e) {
                    o.setData({
                        xpznr: e.data, xpzcslb: true, xpzcslbs: false, TabCur: t.currentTarget.dataset.id,
                        scrollLeft: (t.currentTarget.dataset.id - 1) * 50,
                    })
                },
            });//小瓶子列表
        }
        else {
            e = 1;
            var bfcs = new Array(), j = 0;
            if (app.globalData.csnr != null) {
                for (var i = 0; app.globalData.csnr[i]; i++) {
                    if (app.globalData.csnr[i][7] == t.currentTarget.dataset.id) {
                        bfcs[j] = app.globalData.csnr[i];
                        j++;
                    }
                }
                o.setData({
                    csnr: bfcs,
                    xpzcslb: false, xpzcslbs: true,
                    TabCur: t.currentTarget.dataset.id,
                    scrollLeft: (t.currentTarget.dataset.id - 1) * 50,
                })
            } else {
                wx.request({
                    url: app.globalData.url + "ndzscs/request1/main2.php",
                    method: "GET",
                    data: {
                        tm: t.currentTarget.dataset.id
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function (e) {
                        o.setData({
                            csnr: e.data,
                            xpzcslb: false, xpzcslbs: true,
                            TabCur: t.currentTarget.dataset.id,
                            scrollLeft: (t.currentTarget.dataset.id - 1) * 50,
                        })
                    },
                });
            }
        }
    },//导航栏
    xpzkscs: function (t) {
        var o = t.currentTarget.dataset.index;
        wx.navigateTo({
            url: "/pages/ceshi/ceshi?tm=" + this.data.xpznr[o][1] + "&tp=" + this.data.xpznr[o][4] + "&bjtp=" + this.data.xpznr[o][5] + "&xxjs=" + this.data.xpznr[o][3] + "&num=" + this.data.xpznr[o][0] + "&xpzcs=1" + "&zdy=0" + "&csrs=null"
        });
    },//小瓶子开始测试
});